#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
	int n;
	cin >> n;

	multimap<int, string, greater<int>> students;
	
	for (int i = 0;i < n;i++)
	{
		string name;
		int score;
		cin >> name >> score;
		students.insert({ score,name });
	}

	for (const auto& student : students)
	{
		cout << student.second << " " << student.first << endl;
	}

	return 0;
}